Skip to content

Get type from auto with index operator#4826

Merged
firewave merged 9 commits intocppcheck-opensource:mainfrom
chrchr-github:chr_typedecl
Feb 28, 2023
Merged

Get type from auto with index operator#4826
firewave merged 9 commits intocppcheck-opensource:mainfrom
chrchr-github:chr_typedecl

Conversation

@chrchr-github
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/token.cpp Outdated
while (Token::Match(varTok, "%name% ::"))
varTok = varTok->tokAt(2);
while (Token::simpleMatch(varTok, "["))
varTok = varTok->astOperand1();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typeDecl of an index expression shouldn't be the decl of the container.

Comment thread test/testfunctions.cpp

check("void f(std::vector<std::unordered_map<int, std::unordered_set<int>>>& v, int i, int j) {\n"
" auto& s = v[i][j];\n"
" s.insert(0);\n"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be test that the valueType of s is unordered_set.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the ValueType was correct all along, but we don't use that when looking up member functions.
I have added a test where there is no ambiguity between containers.

@chrchr-github chrchr-github marked this pull request as draft February 25, 2023 20:39
@chrchr-github chrchr-github marked this pull request as ready for review February 25, 2023 22:53
@firewave firewave merged commit 17e7768 into cppcheck-opensource:main Feb 28, 2023
@chrchr-github chrchr-github deleted the chr_typedecl branch March 13, 2023 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants